/*
https://leetcode-cn.com/problems/minimum-number-of-k-consecutive-bit-flips/solution/k-lian-xu-wei-de-zui-xiao-fan-zhuan-ci-s-bikk/
 */
public class Solution995 {
    public int minKBitFlips(int[] nums, int k) {
        int[] dif=new int[nums.length+1];
        int now=0;
        int ans=0;
        for (int i=0;i<nums.length;i++){
            now=now+dif[i];
            if ((nums[i]+now)%2==0){
                if (i+k>nums.length){
                    return -1;
                }
                ans++;
                dif[i+k]--;
                now++;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution995().minKBitFlips(new int[]{0,1,0},1));
    }
}
